//
//  MainViewController.swift
//  wmyweibo
//
//  Created by 王明玉 on 16/1/13.
//  Copyright © 2016年 王明玉. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    //MARK 添加监听事件
    func plusBtnDidClick(){
        print(__FUNCTION__)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        //系统的tabBar是 只读属性 不能直接修改
        //可以使用kvc 简介修改
        print(tabBar.classForCoder)
        
        addChildViewControllers()
        
        
        let mainTabbar = MainTabBar()
        setValue(mainTabbar, forKey: "tabBar")
        mainTabbar.plusBtn.addTarget(self, action: "plusBtnDidClick", forControlEvents: .TouchUpInside)
    }

   //添加子视图控制器
    func addChildViewControllers(){
        addChildViewController(HomeTableViewController(),imageName: "tabbar_home", title: "首页")
        addChildViewController(MessageTableViewController(),imageName: "tabbar_message_center", title: "消息")
        addChildViewController(DiscoverTableViewController(),imageName: "tabbar_discover", title: "发现")
        addChildViewController(ProfileTableViewController(),imageName: "tabbar_profile", title: "我")
    }
   func  addChildViewController(vc:UIViewController,imageName:String,title:String) {
        //实例化一个homecontroller
        //let vc = HomeTableViewController()
    
        let nav = UINavigationController(rootViewController: vc)
        
        vc.title = title
        
       vc.tabBarItem.image = UIImage(named: imageName)
    vc.tabBarItem.selectedImage = UIImage(named: imageName+"_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
    
//        vc.tabBarItem.title = title
//        vc.navigationItem.title = "zhsss"
        addChildViewController(nav)
    }
    

    
}
